package com.polytech.web.client.service;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.polytech.web.client.model.Person;

public class PersonUserCallBack implements AsyncCallback<Person> {

	private VerticalPanel vPanel;
	TextBox lastName;
	TextBox birthDay;
	TextBox country;
	TextBox workPlace;
	TextBox school;
	Image image;

	public PersonUserCallBack(VerticalPanel vPanel, TextBox birthDay, TextBox country, TextBox workPlace, Image image,TextBox school ) {
		this.vPanel = vPanel;
		this.birthDay = birthDay;
		this.country = country;
		//this.lastName = lastName;
		this.workPlace = workPlace;
		this.image=image;
		this.school=school;
	}

	public void onFailure(Throwable caught) {
		Window.alert(caught.getMessage());
	}

	public void onSuccess(Person result) {
		if (result != null) {
			vPanel.setVisible(true);
			Person user = result;
			if (user != null) {
				birthDay.setText(user.getUserBirthday());
				country.setText(user.getUserCountry());
				//lastName.setText(user.getUserLastname());
				workPlace.setText(user.getUserWorkPlace());
				image.setUrl(user.getUserImg());
				school.setText(user.getUserSchool());
				birthDay.setEnabled(false);
				country.setEnabled(false);
				//lastName.setEnabled(false);
				workPlace.setEnabled(false);
				school.setEnabled(false);
				
			}
		}
	}


}
